<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
      .active {
        color: white;
        background-color: black;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button :class="{active:num==1}" @click="tip(1)">按钮</button>
      <button :class="{active:num==2}" @click="tip(2)">按钮</button>
      <button :class="{active:num==3}" @click="tip(3)">按钮</button>
      <hr />
      <button v-for="x in 3" :class="{active:num==x}" @click="tip(x)">
        按钮
      </button>
    </div>
  </body>
  <script>
    let app = Vue.createApp({
      data() {
        return {
          num: 1,
        };
      },
      methods: {
        tip(a) {
          this.num = a;
        },
      },
    });
    app = app.mount("#app");
  </script>
</html>
